<?php

class Core_Validate_Match extends Zend_Validate_Abstract
{
	const MSG_MATCH = 'match';
	
	protected $_match = '';
	protected $_prefix = '';
	
	protected $_messageVariables = array(
			'prefix' => '_prefix'
	);

	protected $_messageTemplates = array(
		self::MSG_MATCH 	=> "Must be match '%prefix%'",
	);
	
	public function __construct($match = '', $prefix = '')
	{
		$this->_match = $match;
		$this->_prefix = empty($prefix)?(is_array($match)?implode(',', $match):$match):$prefix;
	}

	public function isValid($value)
	{
		$this->_setValue($value);
		
		if(($this->_match == $value) || @in_array($value, $this->_match))
		{
			return true;
		}
		$this->_error(self::MSG_MATCH);
	}
}